<?php
include("inc/db_connect.php");
include("inc/functions.php");

$z = array();
$d = array();

$zam_where = '';
if (!empty($_GET['zam']))
    $zam_where = " WHERE zam='".$_GET['zam']." '";

$zam_s = "SELECT * FROM vystup $zam_where GROUP BY zam ORDER BY date ASC";
$zam_q = MySQL_Query ($zam_s);
$pz = 0;
while ($zam = MySQL_Fetch_Array ($zam_q)) {
    $z[$pz] += $zam['zam'];
    $pz ++;
}

$pd = 0;
$dat_s = "SELECT * FROM vystup GROUP BY date ORDER BY date ASC";
$dat_q = MySQL_Query ($dat_s);
while ($zam = MySQL_Fetch_Array ($dat_q)) {
    $d[$pd] = $zam['date'];
    $pd ++;
}

echo '<table style="border-collapse: collapse">';
echo '<tr>';
echo '<td style="border: 1px solid black"></td>';
for ($i=0;$i<$pd;$i++) {
    echo '<td style="border: 1px solid black">'.$d[$i].'</td>';
}
echo '</tr>';
for ($i=0;$i<$pz;$i++) {
    echo '<tr>';
    echo '<td style="border: 1px solid black">';
    $zam_s = "SELECT * FROM z WHERE id='".$z[$i]."'";
    $zam_q = MySQL_Query ($zam_s);
    while ($zam = MySQL_Fetch_Array ($zam_q)) {
        echo $zam['id'];
        echo ' ';
        echo $zam['meno'];
        echo ' ';
        echo $zam['priezvisko'];
        echo ' ';
        echo $zam['manager'];
    }
    echo '</td>';
    for ($j=0;$j<$pd;$j++) {
        echo '<td style="text-align: center;border: 1px solid black">';
        $data_s = "SELECT * FROM vystup WHERE date='".$d[$j]."' AND zam='".$z[$i]."'";
        $data_q = MySQL_Query ($data_s);
        while ($data = MySQL_Fetch_Array ($data_q)) {
            echo "nadcas: " .$data['value'];
            echo '|';
            echo "mal byt v praci/na co kontrolujem: " .$data['full'];
            echo '|';
            echo "smien: " .$data['smeny'];
            echo '|';
            echo "pn: " .$data['pn'];
        }
        echo '</td>';
    }
    echo '</tr>';
}
echo '</table>';
?>

